﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using Microsoft.Practices.Prism.Interactivity;
using Microsoft.Practices.Prism.UnityExtensions;
using System.Collections.ObjectModel;
using Module.Model;
using System.Windows.Controls;
using System.Windows;

namespace Module.ViewModel
{
    class ModuleAViewModel: INotifyPropertyChanged
    {
        #region Data

        public ObservableCollection<PersonViewModel> _persons { get; set; }
        private Visibility _canEnable;

        #endregion Data

        #region Constructor

        public ModuleAViewModel()
        {
            createListPerson();
            CanEnable = Visibility.Collapsed;
            Global.ModuleAViewModel = this;
        }

        private void createListPerson()
        {
            _persons = new ObservableCollection<PersonViewModel>();

            Person jacky = new Person("Jacky");

            Person lilly = new Person("Lilly");
            Person john = new Person("John");
            jacky.Children = new List<Person> { lilly, john };

            PersonViewModel jackyModel = new PersonViewModel(jacky);

            _persons.Add(jackyModel);
        }

        public ObservableCollection<PersonViewModel> Persons
        {
            get
            {
                return _persons;
            }
            set
            {
                if (this._persons != value)
                {
                    this._persons = value;
                    NotifyPropertyChanged("Persons");
                }
            }
        }

        public Visibility CanEnable
        {
            get { return _canEnable; }
            set
            {
                _canEnable = value;
                NotifyPropertyChanged("CanEnable");
            }
        }

        #endregion Constructor

        #region NotifyPropertyChanged Member
        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
        #endregion NotifyPropertyChanged Member
    }
}
